/*
 * Copyright 2002-2006 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.jwtools.tmt.ui;

import java.awt.Dimension;
import java.util.Iterator;

import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

import net.jwtools.tmt.domain.Territory;

import org.jdesktop.swingx.JXLabel;
import org.springframework.binding.value.ValueModel;
import org.springframework.binding.value.support.ValueHolder;
import org.springframework.richclient.form.AbstractForm;
import org.springframework.richclient.form.binding.Binding;
import org.springframework.richclient.form.binding.swing.ListBinding;
import org.springframework.richclient.form.binding.swing.SwingBindingFactory;
import org.springframework.richclient.form.builder.TableFormBuilder;

/**
 * Form to handle the properties of a Contact object. It uses a
 * {@link TableFormBuilder} to construct the layout of the form. Contact object
 * properties are easily bound to UI controls using the form builder's
 * {@link TableFormBuilder#add(String)} method. The platform takes care of
 * determining which kind of control to create based on the type of the property
 * in question.
 * 
 * @author Larry Streepy
 */
public class TerritoryInfoForm extends AbstractForm {
	public TerritoryInfoForm(Territory territory) {
		super(territory);
		setId("territory");
	}

	protected JComponent createFormControl() {
		SwingBindingFactory bf = (SwingBindingFactory)getBindingFactory();
		TableFormBuilder formBuilder = new TableFormBuilder(bf);
		formBuilder.setLabelAttributes("colGrId=label valign=top");
		bf.getFormModel().getFieldMetadata("info").setReadOnly(true);
		formBuilder.addSeparator("Info");
		formBuilder.row();
		formBuilder.add("number", new JLabel());
		formBuilder.row();
		formBuilder.add("description",new JXLabel());
		JScrollPane isp = new JScrollPane(new JEditorPane("text/html", ""));
		
		isp.setPreferredSize(new Dimension(200,150));
		isp.setMaximumSize(new Dimension(200,150));
		formBuilder.row();
		formBuilder.add("info", isp);
		return formBuilder.getForm();
	}

	/**
	 * Try to place the focus in the firstNameField whenever the initial focus
	 * is being set.
	 * 
	 * @return
	 */
	public boolean requestFocusInWindow() {
		return this.requestFocusInWindow();
	}
}